<template>
	<view>
		<u-navbar :border-bottom="false" title="员工管理" :title-size="36" :title-bold="true" :title-color="textColor" :background="{backgroundColor: bgColor}">
		</u-navbar>
		<view class="u-m-b-20">
			<u-cell-group :border="false">
				<u-cell-item v-for="(item, index) in list" :key="index" :title="item.name" :value="item.shopPositionName" @click="toPage('ziliao', item)"></u-cell-item>
			</u-cell-group>
		</view>
		<set-submit-bt text="添加员工" @click="typeShow = true" bgColor="#F8F8F8" />
		<!-- 操作菜单 -->
		<u-action-sheet :list="typeList" v-model="typeShow" @click="handleSubmit"></u-action-sheet>
		<akLoading isFullScreen :active="loading"></akLoading>
	</view>
</template>

<script>
	import SetSubmitBt from '@/components/set-submit-bt/index.vue'
	export default {
		components: { SetSubmitBt },
		data() {
			return {
				labelStyle: {
					fontSize: '30rpx',
				},
				buttonStyle: {
					height: '90rpx',
					color: '#FFFFFF',
					background: this.linearGradient
				},
				params: {
					ShopId: '',
					PageIndex: 1,
					PageSize: 50
				},
				list: [],
				typeShow: false,
				loading: false,
				shopId:'',
				typeList: [
					{
						text: '手机号添加'
					},
					{
						text: '扫码添加'
					}
				]
				
			}
		},
		onLoad(options) {
			this.shopId = options.shopId;
			this.params.ShopId =  options.shopId;
			// 获取职位列表
			this.getEmployeeList()
		},
		onShow() {
			this.getEmployeeList()
		},
		methods: {
			async getEmployeeList() {
				this.loading = true;
				const res = await this.$setHttp.get('api/Shop/PageShopEmployee', { params: this.params , header:{shopId:this.shopId}});
				this.loading = false;
				this.list = res.data.list
			},
			handleSubmit(index) {
				if (index == 1) {
					uni.scanCode({
						success: async (res) => {
							const result = await this.$setHttp.get('api/Shop/QRShopEmployee', {  header:{shopId:this.shopId},params: { qRcode: res.result, shopId: this.shopId } })
							if (!result.data) return;
							await this.$nextTick();
							setTimeout(() => {
								this.$mRouter.push({ route: '/pages/purchase/shezhi/ziliao?qrcode=' + res.result+'&shopId='+this.shopId })
							},800)
						},
						fail:err=>{
							this.$u.toast('识别员工二维码失败，请重新扫码或使用手机号添加')
						}
					});
				} else {
					this.$mRouter.push({ route: '/pages/purchase/shezhi/ziliao?shopId='+this.shopId })
				}
			},
			toPage(page, item) {
				// const info = {
				// 	employeeId: item.id,
				// 	userId: item.userId,
				// 	shopPositionName: item.shopPositionName
				// }
				// this.$store.dispatch('shop/setUserCard', info)
				this.$mRouter.push({ route: this.$mHelper.objParseUrlAndParam('/pages/purchase/shezhi/ziliao', {id:item.id, userId: item.userId, shopPositionName: item.shopPositionName,shopId:this.shopId }) })
				
			}
		}
	}
</script>

<style lang="scss" scoped>
</style>
